package cn.com.cetccst.usercenter;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import cn.com.cetccst.datacenter.message.InboxMessageRespository;
import cn.com.cetccst.usercenter.model.UserInfoModel;
import cn.com.cetccst.usercenter.network.UserCenterHttpRequester;

public class UserInfoViewModel extends ViewModel {
    //todo 从DB获取数据
    public MutableLiveData<UserInfoModel> userInfo = new MutableLiveData<>();

    public LiveData<Integer> unreadMsgCount = InboxMessageRespository.getInstance().getUnreadCount();

    public void getUserInfo() {
        UserCenterHttpRequester.getInstance().geUserInfo()
                .map(response -> {
                    UserInfoModel model = new UserInfoModel();
                    model.setUserName(response.getAccount());
                    model.setDepartment(response.getTenantName());
                    model.setUserPhoneNumber(response.getPhone());
                    return model;
                })
                .subscribe((userInfoModel -> {
                    //todo 存储DB
                }));
    }

}
